// vue注册事件 定义全局方法
import lodash from 'lodash'
import CryptoJS from 'crypto-js'
import numeral from 'numeral'
import anime from 'animejs'
import dayjs from 'dayjs'
import filter from './filter'
import tools from './tools'
import 'dayjs/locale/zh-cn'
import { mapActions, mapGetters, mapMutations, mapState } from 'vuex'
import jtApi from '@/assets/js/api/jinTang'
import tzApi from '@/assets/js/api/taiZhou'
import childrenApi from '@/assets/js/api/children'
import iconographyApi from '@/assets/js/api/iconography'
import baiduApi from '@/assets/js/api/baidu'
import oneCardApi from '@/assets/js/api/oneCard'
import wx from 'wx'
import { Base64 } from 'js-base64'

dayjs.locale('zh-cn')

// 注册插件到全局
export default {
	install: function(Vue) {
		Vue.prototype._ = lodash // 对象操作 lodash
		Vue.prototype.crypto = CryptoJS // crypto加密
		Vue.prototype.numeral = numeral // 数字处理
		Vue.prototype.anime = anime // animeJs动画
		Vue.prototype.dayjs = dayjs // 时间格式化
		Vue.prototype.filter = filter // 全局过滤方法
		Vue.prototype.tools = tools // 全局工具
		Vue.prototype.mapActions = mapActions
		// 全局API
		Vue.prototype.api = {
			jtApi,
			tzApi,
			childrenApi,
			iconographyApi,
			baiduApi,
			oneCardApi
		}
		Vue.prototype.wx = wx // 全局挂载微信
		// alert
		Vue.prototype.showModal = options => {
			wx.showModal({
				title: options.title,
				content: options.content,
				confirmColor: '#3D8CFF',
				confirmText: options.confirmText,
				success(res) {
					if (res.confirm) {
						options.success()
					} else if (res.cancel) {
					}
				}
			})
		}
		// 开启加载动画
		Vue.prototype.showLoading = () => {
			wx.showLoading({
				title: '加载中',
				mask: true
			})
		}
		Vue.prototype.showLoading = () => {
			wx.hideLoading()
		}
		// toast提示
		Vue.prototype.showToast = (text, icon) => {
			wx.showToast({
				title: text,
				icon: icon || 'none',
				duration: 1500
			})
		}

		// atob 转base64
		Vue.prototype.atob = res => {
			return Base64.encode(res)
		}
		// btoa base64解密
		Vue.prototype.btoa = res => {
			return Base64.decode(res)
		}
	}
}
